package org.come.summonequip;

import java.awt.Color;
import java.awt.Dimension;
import java.awt.Graphics;

import javax.swing.BorderFactory;
import javax.swing.ImageIcon;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.ScrollPaneConstants;

import org.cbg.until.TraslationDemoScrollBarUI;
import org.come.Jpanel.GoodsMsgJpanel;
import org.come.bean.QualityClBean;
import org.come.bean.Skill;
import org.come.until.CutButtonImage;
import org.come.until.SrcollPanelUI;
import org.come.until.UserMessUntil;

import com.tool.tcpimg.RichLabel;
import com.tool.tcpimg.UIUtils;



/**
 * 替换技能主面板
 * <p>
 * Title : JpanelReclaimSkillMain
 * </p>
 *
 * @author : HGC
 * @date : 2019年7月29日 上午9:57:46
 * @version : 1.0.0
 */
public class JpanelReclaimSkillMain extends JPanel {

    /**
     * 原觉醒技名称leftName<br>
     * 新觉醒技名称rightName<br>
     */
    private JLabel leftName, rightName;

    /**
     * 原觉醒度leftDegree<br>
     * 新觉醒度rightDegree<br>
     */
    private JLabel[] leftDegree, rightDegree;

    /**
     * 原觉醒技介绍leftPane<br>
     * 新觉醒技介绍rightPane<br>
     */
    private JScrollPane leftPane, rightPane;

    /**
     * 40保留原技能retainBtn<br>
     * 41替换新技能replaceBtn<br>
     */
    private BtnSummonEquipMain retainBtn, replaceBtn;

    /** 保存新属性 */
    private QualityClBean qualityClBean;

    public JpanelReclaimSkillMain() {
        setPreferredSize(new Dimension(478, 316));
        setOpaque(false);
        setLayout(null);

        getLeftName();
        getRightName();
        getLeftDegree();
        getRightDegree();
        getLeftPane();
        getRightPane();
        getRetainBtn();
        getReplaceBtn();
    }

    /** 拆解觉醒技字符串放到重洗技能面板 */
    public void washSkillViewgetMessage(String valueMessage, int type) {
        String[] split = valueMessage.split("&");
        double parseDouble = Double.parseDouble(split[2]);
        int max = (int) parseDouble;
        double num = parseDouble - max;
        Skill skill = UserMessUntil.getSkillId(split[1]);
        if (type == 0) {
            leftName.setText(skill.getSkillname() + "(" + parseDouble + ")");
            RichLabel view = (RichLabel) leftPane.getViewport().getView();
            long lvl = JpanelSummonEquipMain.expChangeLevel(Long.parseLong(split[3]));
            view = new RichLabel(GoodsMsgJpanel.SummonSkillRemark("#G" + skill.getRemark(), skill, split[2], lvl + ""),
                    UIUtils.TEXT_FONT2);
            Dimension d = view.computeSize(145);
            view.setSize(d);
            view.setPreferredSize(d);
            leftPane.setViewportView(view);
            for (int i = 0; i < leftDegree.length; i++) {
                if ((i + 1) <= max) {
                    leftDegree[i].setIcon(CutButtonImage.getImage("inkImg/hongmu/2/经验_星_满_w15,h16.png", 15, 16));
                } else {
                    leftDegree[i].setIcon(CutButtonImage.getImage("inkImg/hongmu/2/经验_星_无_w15,h16.png", 15, 16));
                }
            }
            if (max == 5) {
                return;
            }
            if (num < 0.2) {
                leftDegree[max].setIcon(CutButtonImage.getImage("inkImg/hongmu/2/经验_星_无_w15,h16.png", 15, 16));
            } else if (num > 0.8) {
                leftDegree[max].setIcon(CutButtonImage.getImage("inkImg/hongmu/2/经验_星_满_w15,h16.png", 15, 16));
            } else {
                leftDegree[max].setIcon(CutButtonImage.getImage("inkImg/hongmu/2/经验_星_半_w15,h16.png", 15, 16));
            }

        } else {
            rightName.setText(skill.getSkillname() + "(" + parseDouble + ")");
            RichLabel view = (RichLabel) rightPane.getViewport().getView();
            long lvl = JpanelSummonEquipMain.expChangeLevel(Long.parseLong(split[3]));
            view = new RichLabel(GoodsMsgJpanel.SummonSkillRemark("#G" + skill.getRemark(), skill, split[2], lvl + ""),
                    UIUtils.TEXT_FONT2);
            Dimension d = view.computeSize(145);
            view.setSize(d);
            view.setPreferredSize(d);
            rightPane.setViewportView(view);
            for (int i = 0; i < rightDegree.length; i++) {
                if ((i + 1) <= max) {
                    rightDegree[i].setIcon(CutButtonImage.getImage("inkImg/hongmu/2/经验_星_满_w15,h16.png", 15, 16));
                } else {
                    rightDegree[i].setIcon(CutButtonImage.getImage("inkImg/hongmu/2/经验_星_无_w15,h16.png", 15, 16));
                }
            }
            if (max == 5) {
                return;
            }
            if (num < 0.2) {
                rightDegree[max].setIcon(CutButtonImage.getImage("inkImg/hongmu/2/经验_星_无_w15,h16.png", 15, 16));
            } else if (num > 0.8) {
                rightDegree[max].setIcon(CutButtonImage.getImage("inkImg/hongmu/2/经验_星_满_w15,h16.png", 15, 16));
            } else {
                rightDegree[max].setIcon(CutButtonImage.getImage("inkImg/hongmu/2/经验_星_半_w15,h16.png", 15, 16));
            }

        }
    }

    private ImageIcon iconBack;

    @Override
    protected void paintComponent(Graphics g) {
        // TODO Auto-generated method stub
        super.paintComponent(g);
        if (iconBack == null) {
            iconBack = new ImageIcon("inkImg/old/background/S135.png");
        }
        g.drawImage(iconBack.getImage(), 0, 0, 478, 316, this);
        g.setColor(Color.white);
        g.setFont(UIUtils.TEXT_FONT1);
        g.drawString("觉醒度", 59, 93 + 13);
        g.drawString("觉醒度", 261, 93 + 13);
    }

    public ImageIcon getIconBack() {
        return iconBack;
    }

    public void setIconBack(ImageIcon iconBack) {
        this.iconBack = iconBack;
    }

    public JLabel getLeftName() {
        if (leftName == null) {
            leftName = new JLabel();
            leftName.setBounds(59, 64, 164, 22);
            leftName.setForeground(Color.white);
            leftName.setFont(UIUtils.TEXT_FONT1);
            leftName.setOpaque(false);
            this.add(leftName);
        }
        return leftName;
    }

    public void setLeftName(JLabel leftName) {
        this.leftName = leftName;
    }

    public JLabel getRightName() {
        if (rightName == null) {
            rightName = new JLabel();
            rightName.setBounds(261, 64, 164, 22);
            rightName.setForeground(Color.white);
            rightName.setFont(UIUtils.TEXT_FONT1);
            rightName.setOpaque(false);
            this.add(rightName);
        }
        return rightName;
    }

    public void setRightName(JLabel rightName) {
        this.rightName = rightName;
    }

    public JLabel[] getLeftDegree() {
        if (leftDegree == null) {
            leftDegree = new JLabel[5];
            for (int i = 0; i < leftDegree.length; i++) {
                leftDegree[i] = new JLabel();
                leftDegree[i].setIcon(CutButtonImage.getImage("inkImg/hongmu/2/经验_星_满_w15,h16.png", 15, 16));
                leftDegree[i].setBounds(59 + 47 + i * 22, 93, 15, 16);
                this.add(leftDegree[i]);
            }
        }
        return leftDegree;
    }

    public void setLeftDegree(JLabel[] leftDegree) {
        this.leftDegree = leftDegree;
    }

    public JLabel[] getRightDegree() {
        if (rightDegree == null) {
            rightDegree = new JLabel[5];
            for (int i = 0; i < rightDegree.length; i++) {
                rightDegree[i] = new JLabel();
                rightDegree[i].setIcon(CutButtonImage.getImage("inkImg/hongmu/2/经验_星_满_w15,h16.png", 15, 16));
                rightDegree[i].setBounds(261 + 47 + i * 22, 93, 15, 16);
                this.add(rightDegree[i]);
            }
        }
        return rightDegree;
    }

    public void setRightDegree(JLabel[] rightDegree) {
        this.rightDegree = rightDegree;
    }

    public JScrollPane getLeftPane() {
        if (leftPane == null) {
            leftPane = new JScrollPane();
            leftPane.setVerticalScrollBarPolicy(22);
            leftPane.getVerticalScrollBar().setUI(new TraslationDemoScrollBarUI(this.leftPane));
            leftPane.getVerticalScrollBar().setUnitIncrement(30);
            leftPane.getViewport().setOpaque(false);
            leftPane.setOpaque(false);
            leftPane.setBounds(59, 118, 178 + 3, 100);
            leftPane.setBorder(BorderFactory.createEmptyBorder());
            leftPane.setHorizontalScrollBarPolicy(31);
            this.add(leftPane);
        }
        return leftPane;
    }

    public void setLeftPane(JScrollPane leftPane) {
        this.leftPane = leftPane;
    }

    public JScrollPane getRightPane() {
        if (rightPane == null) {
            rightPane = new JScrollPane();
            rightPane.setVerticalScrollBarPolicy(22);
            rightPane.getVerticalScrollBar().setUI(new TraslationDemoScrollBarUI(this.rightPane));
            rightPane.getVerticalScrollBar().setUnitIncrement(30);
            rightPane.getViewport().setOpaque(false);
            rightPane.setOpaque(false);
            rightPane.setBounds(261, 118, 178 + 3, 100);
            rightPane.setBorder(BorderFactory.createEmptyBorder());
            rightPane.setHorizontalScrollBarPolicy(31);
            this.add(rightPane);
        }
        return rightPane;
    }

    public void setRightPane(JScrollPane rightPane) {
        this.rightPane = rightPane;
    }

    public BtnSummonEquipMain getRetainBtn() {
        if (retainBtn == null) {
            retainBtn = new BtnSummonEquipMain("skin/8100226/newbutton/B21.png", 1, UIUtils.COLOR_WHITE2, UIUtils.TEXT_HY16,
                    "保 留", 40, this);
            retainBtn.setBounds(98, 238, 79, 24);
            this.add(retainBtn);
        }
        return retainBtn;
    }

    public void setRetainBtn(BtnSummonEquipMain retainBtn) {
        this.retainBtn = retainBtn;
    }

    public BtnSummonEquipMain getReplaceBtn() {
        if (replaceBtn == null) {
            replaceBtn = new BtnSummonEquipMain("skin/8100226/newbutton/B21.png", 1, UIUtils.COLOR_WHITE2, UIUtils.TEXT_HY16,
                    "替 换", 41, this);
            replaceBtn.setBounds(309, 238, 79, 24);
            this.add(replaceBtn);
        }
        return replaceBtn;
    }

    public void setReplaceBtn(BtnSummonEquipMain replaceBtn) {
        this.replaceBtn = replaceBtn;
    }

    public QualityClBean getQualityClBean() {
        return qualityClBean;
    }

    public void setQualityClBean(QualityClBean qualityClBean) {
        this.qualityClBean = qualityClBean;
    }

}
